package com.xtianzhuang.www.study2019.plugin;

import org.mybatis.generator.api.IntrospectedColumn;
import org.mybatis.generator.api.IntrospectedTable;
import org.mybatis.generator.api.dom.java.Field;
import org.mybatis.generator.api.dom.java.Method;
import org.mybatis.generator.api.dom.java.TopLevelClass;
import org.mybatis.generator.internal.DefaultCommentGenerator;

/**
 * 生成model中，字段增加注释
 */
public class CommentGenerator extends DefaultCommentGenerator {

	@Override
	public void addFieldComment(Field field, IntrospectedTable introspectedTable,
			IntrospectedColumn introspectedColumn) {
		super.addFieldComment(field, introspectedTable, introspectedColumn);
		field.addJavaDocLine("/**");
		if (introspectedColumn.getRemarks() != null && !"".equals(introspectedColumn.getRemarks())) {
			field.addJavaDocLine("\0* " + introspectedColumn.getRemarks());
		}
		field.addJavaDocLine(" *  this field corresponds to the database column "
				+ introspectedColumn.getActualColumnName() + "; length:" + introspectedColumn.getLength());
		// if (introspectedColumn.isAutoIncrement()) {
		// field.addJavaDocLine("\0* this field is autoIncrement");
		// }
		// if (introspectedColumn.isNullable()) {
		// field.addJavaDocLine(" * this field is nullable");
		// } else {
		// field.addJavaDocLine(" * " + " This field is not null");
		// }
		field.addJavaDocLine(" */");

	}

	@Override
	public void addGetterComment(Method method, IntrospectedTable introspectedTable,
			IntrospectedColumn introspectedColumn) {
		// TODO Auto-generated method stub
		super.addGetterComment(method, introspectedTable, introspectedColumn);
		method.addJavaDocLine("/**");
		if (introspectedColumn.getRemarks() != null && !"".equals(introspectedColumn.getRemarks())) {
			method.addJavaDocLine("\0* " + introspectedColumn.getRemarks());
		}
		// method.addJavaDocLine(" *" + " this method returns the value of the database column "
		// + introspectedColumn.getActualColumnName());
		method.addJavaDocLine(" */");


	}

	@Override
	public void addSetterComment(Method method, IntrospectedTable introspectedTable,
			IntrospectedColumn introspectedColumn) {
		// TODO Auto-generated method stub
		super.addSetterComment(method, introspectedTable, introspectedColumn);
		if (introspectedColumn.getRemarks() != null && !"".equals(introspectedColumn.getRemarks())) {
			method.addJavaDocLine("/**");
			method.addJavaDocLine("\0*" + introspectedColumn.getRemarks());
			method.addJavaDocLine(" */");
		}
	}

	@Override
	public void addModelClassComment(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
		// TODO Auto-generated method stub
		super.addModelClassComment(topLevelClass, introspectedTable);
		if (introspectedTable.getRemarks() != null && !"".equals(introspectedTable.getRemarks())) {
			topLevelClass.addJavaDocLine("/**");
			topLevelClass.addJavaDocLine("\0*" + introspectedTable.getRemarks());
			topLevelClass.addJavaDocLine(" */");
		}
	}


}
